package compare;

import java.math.BigDecimal;
import java.util.stream.Stream;
import org.testng.annotations.Test;

/**
 * @author
 */
public class Utils {

    private static Number unscale(BigDecimal decimal) {
        if (decimal.scale() != 0) {
            return decimal.doubleValue();
        } else {
            return decimal.longValue();
        }
    }

    public static Number plus(Number t1, Number t2, Number... more) {
        return Stream.concat(Stream.of(t1, t2), Stream.of(more))
            .map(Number::doubleValue)
            .map(BigDecimal::valueOf)
            .reduce(BigDecimal::add)
            .map(Utils::unscale)
            .orElse(BigDecimal.ZERO);
    }

    @Test
    private void t1() {
        Number n1 = 1;
        Number n2 = 0.3;
        Number n3 = 1L;

        System.out.println(n1);
        System.out.println(n3);


    }



}
